package com.example.app.components


import android.util.Log
import android.widget.RadioButton
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.material.RadioButton
import androidx.compose.runtime.*
import androidx.compose.ui.tooling.preview.Preview

@Composable
fun RadioButtonSample() {
    var select by remember {
        mutableStateOf(true)
    }
//    Row() {
//        // 单个radio
//        RadioButton(selected = select, onClick = {
//            select = !select
//        })
//    }
    // 多个Radio
    var selectList by remember {
        mutableStateOf(listOf(false, true, false))
    }
    Column() {
        selectList.forEachIndexed{
            i, item ->
                RadioButton(selected = item, onClick = {
                    // 此时改变的是mutableStateOf里面的数组而不是state,不会发生变化
                    // 需要修改整个list
                    selectList = selectList.mapIndexed { j, b ->
                        i == j
                    }
                })
        }
    }
}

@Preview(
    showSystemUi = true
)
@Composable
fun RadioButtonSamplePreview() {
    RadioButtonSample()
}

